"use strict";
var sgcc    = sgcc || {};

$.extend(sgcc, {
  announcement: 0,
  init: function(){
    this.initMenu(); //初始化下拉菜单
    //this.initPanel(); //初始化面板
	this.initOthers(); //初始化友情链接等
	this.initAnnouncement(); //初始化公告
    this.initTab(); //初始化标签页
    this.initMarquee(); //初始化滚动公告
  },
  initMenu: function() {
    $('.menu_item').on('mouseover', function(){
      $(this).find('.item_content').show();
    }).on('mouseout', function(){
      $(this).find('.item_content').hide();
    });
  },
  initPanel: function(){
    $('.cut_top').on('click', function(){
      $('.cut_top.opened').next().slideUp('slow', function(){
        $('.cut_top:not(.opened)').next().slideDown('fast', function(){
          $('.cut_top').toggleClass('opened');
        });
      });
    });
  },
  initOthers: function() {
	$("#friendlink").change(function(){
		if($(this).val() === "")
			return false;
		window.open("http://" + $(this).val(), '_blank');
	});
	$(".hotlines").click(function(){ $("#company_js_tel").show(); });
  },
  initAnnouncement: function() {
	$('div.announcement').each(function(){
		//不足10条的补足10条
		if($(this).find('p').length % 10 !== 0)
		{
			var num = 10 - parseInt($(this).find('p').length / 10);
			
			for(var i=1; i < num; i++)
				$(this).append($('<p>&nbsp;</p>'));
		}
		var div = $(this);
		$(this).find('p:lt(10)').each(function(i, p) {
			$(this).parents('.announcement').append($.clone(p));
		});
	});
	
  },
  initTab: function(){
    $('.Menubox li').on('mouseover', function(){
      if($(this).hasClass('hover'))
        return false;
        
      clearInterval(sgcc.scrollInterval);
      var catalog_id = $(this).attr('data-target');
      $('.Menubox .more').attr('href', $(this).attr('data-link'));
      $('.Menubox li').removeClass('hover');
      $(this).addClass('hover');
      $('.noticeList').stop(true).css('top', 0).empty().removeData()
        .html($('div[data-id="' + catalog_id + '"]').length > 0 ? $('div[data-id="' + catalog_id + '"]').html() : '');
      sgcc.initMarquee();
    });
    $('.noticeList').hover(
      function() {
        clearInterval(sgcc.scrollInterval);
        $('.noticeList').pause();
      }, function() {
        sgcc.scrollInterval = setInterval(sgcc.doScroll, 10000);/**niu update 2014/5/21 :5000->10000**/
        $('.noticeList').resume();
      }
    );
  },
  initMarquee: function() {
    if(!sgcc.inited)
    {
      $('.noticeList').stop().html($('div[data-id="0"]').html());
      sgcc.inited = true;
    }
    $('.noticeList').stop();
    $('.noticeList').data('current', 0);
	$('.noticeList').data('sum', parseInt($('.noticeList p').length / 10));
    sgcc.scrollInterval = setInterval(sgcc.doScroll, 10000);/**niu update 2014/5/21 :5000->10000**/
  },
  doScroll: function(){
    var current = $('.noticeList').data('current') + 1;
    if(current == $('.noticeList').data('sum'))
    {
      current = 1;
      $('.noticeList').css('top', 0);
    }
    $('.noticeList').stop().animate({top:(-current * 250)}, {duration:2000});
    $('.noticeList').data('current', current);
  }
});

$(function () { 
  sgcc.init();
});
//ie6下插入png图片透明
function fixPNG(myImage)  {      var arVersion = navigator.appVersion.split("MSIE");      var version = parseFloat(arVersion[1]);      if ((version >= 5.5) && (version < 7) && (document.body.filters))      {          var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";          var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";          var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' ";          var imgStyle = "display:inline-block;" + myImage.style.cssText;          var strNewHTML = "<span " + imgID + imgClass + imgTitle              + " style=\"" + "width:" + myImage.width              + "px; height:" + myImage.height              + "px;" + imgStyle + ";"            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"            + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";          myImage.outerHTML = strNewHTML;      }  }

